﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mrhd.Database.Migrations.Migrations
{
    public partial class v100 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Sys_Business",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "商户名称"),
                    Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "经营范围"),
                    ImageUrls = table.Column<string>(type: "nvarchar(max)", maxLength: 4098, nullable: true, comment: "图片地址使用 | 分隔"),
                    TaxTitle = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "发票抬头"),
                    TaxNumber = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "税号"),
                    Type = table.Column<int>(type: "int", nullable: false, comment: "企业类型"),
                    Province = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "省份"),
                    City = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "城市"),
                    Address = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "注册地址"),
                    Lat = table.Column<double>(type: "float", nullable: false, comment: "纬度"),
                    Lng = table.Column<double>(type: "float", nullable: false, comment: "经度"),
                    UserCode = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "绑定商户时，推荐员工编码"),
                    ApprovalTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "审核时间"),
                    ApprovalUserId = table.Column<int>(type: "int", nullable: true, comment: "审核人id"),
                    ManagerId = table.Column<int>(type: "int", nullable: true, comment: "商户管理员id"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_Business", x => x.Id);
                },
                comment: "商户");

            migrationBuilder.CreateTable(
                name: "Sys_ProductType",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false, comment: "分类名称"),
                    Sort = table.Column<int>(type: "int", nullable: false, comment: "排序码"),
                    Flag = table.Column<int>(type: "int", nullable: false, comment: "当前标识状态"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_ProductType", x => x.Id);
                },
                comment: "商品分类别");

            migrationBuilder.CreateTable(
                name: "Sys_User",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false, comment: "登录名"),
                    Email = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "邮箱"),
                    Password = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "密码"),
                    Phone = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "手机号"),
                    FullName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "用户全名"),
                    Age = table.Column<int>(type: "int", nullable: false, comment: "年龄"),
                    Gender = table.Column<int>(type: "int", nullable: false, comment: "性别"),
                    Avator = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "头像地址"),
                    IsActive = table.Column<bool>(type: "bit", nullable: false, comment: "是否激活"),
                    IsAdmin = table.Column<bool>(type: "bit", nullable: false, comment: "是否是管理员"),
                    LastLoginTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "最后登录时间"),
                    Code = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "员工编码"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_User", x => x.Id);
                },
                comment: "用户表");

            migrationBuilder.CreateTable(
                name: "Sys_UserMobile",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    OpenId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "小程序的唯一标识"),
                    NickName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "昵称"),
                    FaceUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "头像地址"),
                    Country = table.Column<string>(type: "nvarchar(16)", maxLength: 16, nullable: true, comment: "国家"),
                    Province = table.Column<string>(type: "nvarchar(16)", maxLength: 16, nullable: true, comment: "省份"),
                    City = table.Column<string>(type: "nvarchar(16)", maxLength: 16, nullable: true, comment: "城市"),
                    Gender = table.Column<int>(type: "int", nullable: false, comment: "性别"),
                    Phone = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "手机号"),
                    IsRegister = table.Column<bool>(type: "bit", nullable: false, comment: "是否已经注册"),
                    DefualtBusiness = table.Column<int>(type: "int", nullable: true, comment: "默认商户"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_UserMobile", x => x.Id);
                },
                comment: "移动端用户表");

            migrationBuilder.CreateTable(
                name: "Sys_Product",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false, comment: "商品名称"),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "商品编码"),
                    Logo = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Pinyin = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "名称拼音"),
                    FirstLetter = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "拼音首字母"),
                    Description = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "规格描述"),
                    UnitName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "产品单位"),
                    Price = table.Column<double>(type: "float", nullable: false, comment: "商品单价"),
                    Stock = table.Column<int>(type: "int", nullable: false, comment: "商品库存"),
                    Attributes = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "商品属性"),
                    UPC = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "UPC码"),
                    SKU = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "SKU码"),
                    Status = table.Column<int>(type: "int", nullable: false, comment: "产品状态"),
                    UpTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "上架时间"),
                    DownTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true, comment: "下架时间"),
                    IsDiscount = table.Column<bool>(type: "bit", nullable: false, comment: "是否参与订单折扣活动"),
                    Sort = table.Column<int>(type: "int", nullable: false, comment: "排序码"),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, comment: "是否已删除"),
                    ProductTypeId = table.Column<int>(type: "int", nullable: true, comment: "产品分类id"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_Product", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Sys_Product_Sys_ProductType_ProductTypeId",
                        column: x => x.ProductTypeId,
                        principalTable: "Sys_ProductType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                },
                comment: "商品表");

            migrationBuilder.CreateTable(
                name: "Sys_AccessAuthority",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "路由名称"),
                    UserId = table.Column<int>(type: "int", nullable: true, comment: "绑定的用户"),
                    RoleId = table.Column<int>(type: "int", nullable: true, comment: "绑定的角色"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_AccessAuthority", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Sys_AccessAuthority_Sys_User_UserId",
                        column: x => x.UserId,
                        principalTable: "Sys_User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                },
                comment: "权限描述项");

            migrationBuilder.CreateTable(
                name: "Sys_Address",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Lat = table.Column<double>(type: "float", nullable: false, comment: "纬度"),
                    Lng = table.Column<double>(type: "float", nullable: false, comment: "经度"),
                    Title = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "定位地址"),
                    Detail = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "详细地址"),
                    Phone = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "电话"),
                    Contacts = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "联系人"),
                    UserId = table.Column<int>(type: "int", nullable: true, comment: "关联的用户id"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_Address", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Sys_Address_Sys_User_UserId",
                        column: x => x.UserId,
                        principalTable: "Sys_User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                },
                comment: "用户地址表");

            migrationBuilder.CreateTable(
                name: "Sys_UserMobileToBusiness",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserId = table.Column<int>(type: "int", nullable: false, comment: "用户id"),
                    BusinessId = table.Column<int>(type: "int", nullable: false, comment: "商户id")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_UserMobileToBusiness", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Sys_UserMobileToBusiness_Sys_Business_BusinessId",
                        column: x => x.BusinessId,
                        principalTable: "Sys_Business",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Sys_UserMobileToBusiness_Sys_UserMobile_UserId",
                        column: x => x.UserId,
                        principalTable: "Sys_UserMobile",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                },
                comment: "移动端用户与商户");

            migrationBuilder.CreateTable(
                name: "Sys_ProductImage",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true, comment: "图片url"),
                    ProductId = table.Column<int>(type: "int", nullable: false, comment: "商品id"),
                    CreatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    UpdatedTime = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Sys_ProductImage", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Sys_ProductImage_Sys_Product_ProductId",
                        column: x => x.ProductId,
                        principalTable: "Sys_Product",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "商品图片表");

            migrationBuilder.InsertData(
                table: "Sys_ProductType",
                columns: new[] { "Id", "CreatedTime", "Flag", "Name", "Sort", "UpdatedTime" },
                values: new object[,]
                {
                    { 1, new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), 0, "发热", 1, null },
                    { 2, new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), 0, "头昏", 2, null },
                    { 3, new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), 0, "发炎", 3, null },
                    { 4, new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), 0, "皮肤", 4, null }
                });

            migrationBuilder.InsertData(
                table: "Sys_User",
                columns: new[] { "Id", "Age", "Avator", "Code", "CreatedTime", "Email", "FullName", "Gender", "IsActive", "IsAdmin", "LastLoginTime", "Password", "Phone", "UpdatedTime", "UserName" },
                values: new object[,]
                {
                    { 1, 33, null, "10000001", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "281267775@qq.com", "孙小双", 1, true, true, null, "670b14728ad9902aecba32e22fa4f6bd", "17354300837", null, "sunxsh" },
                    { 2, 32, null, "10000002", new DateTimeOffset(new DateTime(2021, 10, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "345521556@qq.com", "李怡然", 2, true, false, null, "670b14728ad9902aecba32e22fa4f6bd", "18955412235", null, "liyr" },
                    { 3, 27, null, "10000003", new DateTimeOffset(new DateTime(2021, 11, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), "558521145@qq.com", "管理员", 0, true, true, null, "670b14728ad9902aecba32e22fa4f6bd", "13971962638", null, "admin" }
                });

            migrationBuilder.InsertData(
                table: "Sys_UserMobile",
                columns: new[] { "Id", "City", "Country", "CreatedTime", "DefualtBusiness", "FaceUrl", "Gender", "IsRegister", "NickName", "OpenId", "Phone", "Province", "UpdatedTime" },
                values: new object[,]
                {
                    { 1, "武汉", "中国", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, null, 1, true, "华天晓", "123456abc", "17354300837", "湖北", null },
                    { 2, "襄阳", "中国", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 2, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, null, 2, true, "芥", "L41522365", "18956632214", "湖北", null }
                });

            migrationBuilder.InsertData(
                table: "Sys_Product",
                columns: new[] { "Id", "Attributes", "Code", "CreatedTime", "Description", "DownTime", "FirstLetter", "IsDeleted", "IsDiscount", "Logo", "Name", "Pinyin", "Price", "ProductTypeId", "SKU", "Sort", "Status", "Stock", "UPC", "UnitName", "UpTime", "UpdatedTime" },
                values: new object[,]
                {
                    { 1, null, "8020210452809300523", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, null, "999gml", false, false, null, "999感冒灵", "999ganmaoling,999ganmoling", 9.9000000000000004, 1, null, 1, 1, -1, null, "盒", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null },
                    { 2, null, "8020210452809300524", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, null, "amxl,emxl", false, false, null, "阿莫西林", "amoxilin,emoxilin", 20.0, 1, null, 2, 1, -1, null, "盒", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null },
                    { 3, null, "8020210452809300525", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, null, "wsc", false, false, null, "午时茶", "wushicha", 19.899999999999999, 1, null, 3, 1, -1, null, "袋", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null },
                    { 4, null, "8020210452809300526", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, null, "pyp", false, false, null, "皮炎平", "piyanping", 12.5, 4, null, 1, 1, -1, null, "盒", new DateTimeOffset(new DateTime(2021, 9, 21, 8, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null }
                });

            migrationBuilder.CreateIndex(
                name: "IX_Sys_AccessAuthority_UserId",
                table: "Sys_AccessAuthority",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Address_UserId",
                table: "Sys_Address",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Product_Code",
                table: "Sys_Product",
                column: "Code");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Product_FirstLetter",
                table: "Sys_Product",
                column: "FirstLetter");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Product_Name",
                table: "Sys_Product",
                column: "Name");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Product_Pinyin",
                table: "Sys_Product",
                column: "Pinyin");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Product_ProductTypeId",
                table: "Sys_Product",
                column: "ProductTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_Product_Sort",
                table: "Sys_Product",
                column: "Sort");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_ProductImage_ProductId",
                table: "Sys_ProductImage",
                column: "ProductId");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_UserMobileToBusiness_BusinessId",
                table: "Sys_UserMobileToBusiness",
                column: "BusinessId");

            migrationBuilder.CreateIndex(
                name: "IX_Sys_UserMobileToBusiness_UserId",
                table: "Sys_UserMobileToBusiness",
                column: "UserId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Sys_AccessAuthority");

            migrationBuilder.DropTable(
                name: "Sys_Address");

            migrationBuilder.DropTable(
                name: "Sys_ProductImage");

            migrationBuilder.DropTable(
                name: "Sys_UserMobileToBusiness");

            migrationBuilder.DropTable(
                name: "Sys_User");

            migrationBuilder.DropTable(
                name: "Sys_Product");

            migrationBuilder.DropTable(
                name: "Sys_Business");

            migrationBuilder.DropTable(
                name: "Sys_UserMobile");

            migrationBuilder.DropTable(
                name: "Sys_ProductType");
        }
    }
}
